---这个工具类用来解析properties 字符串 或者文件
local StringUtil = require ("util/StringUtil")
local fileUtil = require ("util/FileUtil")
local _M ={}

--解析properties
function _M.parseProperties(propertisStr)
    --ngx.log(ngx.INFO ,"parseProperties str: "..propertisStr);
    local lineArray = StringUtil.split(propertisStr,"\n");
    local resultMap = {}
    --ngx.log(ngx.INFO ,"换行符分割结果 "..#ary);
    for i=1,#lineArray do
        if  lineArray[i] ~= nil then  ---如果为空跳过下一个
            lineArray[i]=StringUtil.trim(lineArray[i]);
            if  StringUtil.startswith(StringUtil,lineArray[i],'#') or StringUtil.startswith(StringUtil,lineArray[i],'-') then
                print("properties content start with comment : "..lineArray[i]);
                goto continue_label;
            end
           -- ngx.log(ngx.INFO ,"准备解析键值对 : "..ary[i].. "类型"..type(ary[i]));
            --if  type(lineArray[i]) == "string" then
            local keyVal = StringUtil.split( lineArray[i],"=")
           -- ngx.log(ngx.INFO ,"键值对才分后的数组长度为 : "..#keyVal);
            print("键值对才分后的数组长度为 : "..#keyVal);
            if keyVal ~=nil and #keyVal==2 then
                resultMap[StringUtil.trim(keyVal[1])]= StringUtil.trim(keyVal[2])
                print("找到properties "..keyVal[1].." value "..keyVal[2]);
                --ngx.log(ngx.INFO ,"找到properties "..keyVal[1].." value "..keyVal[2]);
            end
           -- end
            :: continue_label ::
        end


    end

    return resultMap;


end
--- 读取properties 文件
function _M.readFile(filePath)
    print("parseProperties path: "..filePath);
    local propertisStr =  fileUtil:readFile(filePath)
    -- ngx.log(ngx.INFO ,"parseProperties str: "..propertisStr);
    local resultMap = _M.parseProperties(propertisStr);


    return resultMap;


end



return _M;